<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改违规违纪')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-violate-edit" th:object="${violate}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">姓名：</label>
                <div class="col-sm-8">
                    <input name="name" th:field="*{name}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">事件：</label>
                <div class="col-sm-8">
                    <input id="event" name="event" th:field="*{event}" class="form-control" type="hidden">
                    <div id="editor" class="summernote"></div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">处罚：</label>
                <div class="col-sm-8">
                    <input id="punish" name="punish" th:field="*{punish}" class="form-control" type="hidden">
                    <div id="editor1" class="summernote1"></div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">时间范围：</label>
                <div class="col-sm-8">
                        <div class="input-daterange input-group">
                            <input name="startTime" type="text" class="input-sm form-control" id="laydate-startTime" placeholder="yyyy-MM-dd" th:field="*{startTime}" required/>
                            <span class="input-group-addon">到</span>
                            <input name="endTime" type="text" class="input-sm form-control" id="laydate-endTime" placeholder="yyyy-MM-dd" th:field="*{endTime}"/>
                        </div>
                </div>
            </div>

        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script type="text/javascript">
        var prefix = ctx + "module/violate";
        $("#form-violate-edit").validate({
            focusCleanup: true
        });

        $(function() {
            $('.summernote').summernote({
                placeholder: '请输入内容',
                height : 260,
                lang : 'zh-CN',
                followingToolbar: false,
                callbacks: {
                    onImageUpload: function (files) {
                        sendFile(files[0], this);
                    }
                }
            });
            var content = $("#event").val();
            $('#editor').summernote('code', content);


            $('.summernote1').summernote({
                placeholder: '请输入内容',
                height : 260,
                lang : 'zh-CN',
                followingToolbar: false,
                callbacks: {
                    onImageUpload: function (files) {
                        sendFile(files[0], this);
                    }
                }
            });
            var punish = $("#punish").val();
            $('#editor1').summernote('code', punish);
        });

        function sendFile(file, obj) {
            var data = new FormData();
            data.append("file", file);
            $.ajax({
                type: "POST",
                url: ctx + "common/upload",
                data: data,
                cache: false,
                contentType: false,
                processData: false,
                dataType: 'json',
                success: function(result) {
                    if (result.code == web_status.SUCCESS) {
                        $(obj).summernote('editor.insertImage', result.url, result.fileName);
                    } else {
                        $.modal.alertError(result.msg);
                    }
                },
                error: function(error) {
                    $.modal.alertWarning("图片上传失败。");
                }
            });
        }

        function submitHandler() {
            if ($.validate.form()) {
                var sHTML = $('.summernote').summernote('code');
                $("#event").val(sHTML);

                var punish = $('.summernote1').summernote('code');
                $("#punish").val(punish);
               $.modal.close();
            }
        }
    </script>
</body>
</html>